﻿@using MML.Helpers.Knockout;
@model AppSCO.Models.administracionModel
@{
    ViewBag.Title = "historialPaciente";
    var ko = Html.CreateKnockoutContext();
}


<h1>HISTORIAL DE CITAS EN LINEA</h1>

<table border="0" class="formulario" style="width:400px;" data-bind="with: filtroBusqueda">
    <tr>
        <td style="width:150px;">@Html.LabelFor(c=>c.filtroBusqueda.DNIPAC)</td>
        <td><input type="text" data-bind="value: DNIPAC" style="width:120px;" /></td>
    </tr>
    <tr>
        <td>@Html.LabelFor(c=>c.filtroBusqueda.NOMPAC)</td>
        <td><input type="text" data-bind="value: NOMPAC" style="width:220px;" /></td>
    </tr>
    <tr>
        <td style="text-align:right;" colspan="2"><button data-bind="click: viewModel.buscar">BUSCAR</button></td>
    </tr>
</table><br />


<table class="grilla" style="width:98%;">
    <thead>
        <tr>
            <th>DNI</th>
            <th>PACIENTE</th>
            <th>SEXO</th>
            <th>CELULAR</th>
            <th>CORREO</th>
            <th>FECHA CITA</th>
            <th>HORARIO</th>
            <th>TIPO  DE PAGO</th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody data-bind="foreach: citasGeneradas">
        <tr>
            <td><span data-bind="text: DNIPAC"></span></td>
            <td><span data-bind="text: NOMPAC"></span>&nbsp;<span data-bind="text: APEPPAC"></span>&nbsp;<span data-bind="text: APEMPAC"></span></td>
            <td><span data-bind="text: SEXPAC"></span></td>
            <td><span data-bind="text: TELCPAC"></span></td>
            <td><span data-bind="text: CORPAC"></span></td>
            <td><span data-bind="text: FECCITA"></span></td>
            <td><span data-bind="text: DESHOR"></span></td>
            <td><span data-bind="text: TIPPAG"></span></td>
            
            <td><button data-bind="click: function() { viewModel.verDatos($data); }">SELECCIONAR</button></td>
        </tr>
    </tbody>
    <tfoot data-bind="visible: viewModel.dontResult">
        <tr>
            <td colspan="9">NO SE ENCONTRARON HORARIOS DISPONIBLES</td>
        </tr>
    </tfoot>
</table><br />

@ko.Initialize(Model)
<script type="text/javascript">
    var urlBuscarCitas = '@Url.Action("buscarHistorial","citas")';
    var urlHistorialPaciente = '@Url.Action("historial","file")';

    viewModel.dontResult = ko.observable(true);
    viewModel.buscar = function () {
        var param = ko.toJSON(viewModel.filtroBusqueda);
        $.ajax({
            url: urlBuscarCitas,
            type: "POST",
            async: true,
            data: param,
            contentType: "application/json",
            success: function (result) {
                ko.mapping.fromJS(result.datos, {}, viewModel.citasGeneradas);
                viewModel.dontResult(false);
            },
            error: msgError
        });
    }

    viewModel.verDatos = function (data) {
        openPopup(urlHistorialPaciente + "?Id=" + data.CODCIT(), "", 900, 800);       
    }

 
</script>
@ko.Apply(Model)